"""
插件系统异常

定义插件系统相关的异常类型。
"""

from typing import Optional, Any


class PluginError(Exception):
    """插件系统基础异常"""
    
    def __init__(self, message: str, plugin_name: Optional[str] = None, cause: Optional[Exception] = None):
        super().__init__(message)
        self.plugin_name = plugin_name
        self.cause = cause
    
    def __str__(self) -> str:
        if self.plugin_name:
            return f"插件 '{self.plugin_name}': {super().__str__()}"
        return super().__str__()


class PluginLoadError(PluginError):
    """插件加载异常"""
    
    def __init__(self, message: str, plugin_name: Optional[str] = None, 
                 plugin_path: Optional[str] = None, cause: Optional[Exception] = None):
        super().__init__(message, plugin_name, cause)
        self.plugin_path = plugin_path


class PluginNotFoundError(PluginError):
    """插件未找到异常"""
    pass


class PluginDependencyError(PluginError):
    """插件依赖异常"""
    
    def __init__(self, message: str, plugin_name: Optional[str] = None, 
                 missing_dependencies: Optional[list] = None):
        super().__init__(message, plugin_name)
        self.missing_dependencies = missing_dependencies or []


class PluginVersionError(PluginError):
    """插件版本异常"""
    
    def __init__(self, message: str, plugin_name: Optional[str] = None,
                 required_version: Optional[str] = None, actual_version: Optional[str] = None):
        super().__init__(message, plugin_name)
        self.required_version = required_version
        self.actual_version = actual_version


class PluginInitializationError(PluginError):
    """插件初始化异常"""
    pass


class PluginExecutionError(PluginError):
    """插件执行异常"""
    
    def __init__(self, message: str, plugin_name: Optional[str] = None,
                 method_name: Optional[str] = None, cause: Optional[Exception] = None):
        super().__init__(message, plugin_name, cause)
        self.method_name = method_name


class PluginConfigurationError(PluginError):
    """插件配置异常"""
    
    def __init__(self, message: str, plugin_name: Optional[str] = None,
                 config_key: Optional[str] = None):
        super().__init__(message, plugin_name)
        self.config_key = config_key


class PluginHookError(PluginError):
    """插件钩子异常"""
    
    def __init__(self, message: str, plugin_name: Optional[str] = None,
                 hook_name: Optional[str] = None):
        super().__init__(message, plugin_name)
        self.hook_name = hook_name


class PluginRegistryError(PluginError):
    """插件注册表异常"""
    pass


class PluginConflictError(PluginError):
    """插件冲突异常"""
    
    def __init__(self, message: str, plugin_name: Optional[str] = None,
                 conflicting_plugin: Optional[str] = None):
        super().__init__(message, plugin_name)
        self.conflicting_plugin = conflicting_plugin


class PluginSecurityError(PluginError):
    """插件安全异常"""
    pass


class PluginTimeoutError(PluginError):
    """插件超时异常"""
    
    def __init__(self, message: str, plugin_name: Optional[str] = None,
                 timeout_seconds: Optional[float] = None):
        super().__init__(message, plugin_name)
        self.timeout_seconds = timeout_seconds
